/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package core;

import java.sql.*;

/**
 *
 * @author 13890754-6
 */
public class Query {

    Conexion conn;
    String[][] s;

    public Query(Conexion conn) {
        this.conn = conn;
    }

    public String[][] leeRegistros(String[] campos, String condiciones, String tbls) {
        int x = 0;

        try {

            String stringcampos = "";
            for (int columna = 0; columna < campos.length; columna++) {
                if (columna > 0) {
                    stringcampos += ",";
                }
                stringcampos += campos[columna];
            }
            //  System.out.println("SELECT " + stringcampos + " FROM " + tbls + " WHERE " + condiciones);
            PreparedStatement pstm = conn.getConnection().prepareStatement("SELECT " + stringcampos + " FROM " + tbls + " WHERE " + condiciones);
            ResultSet res = pstm.executeQuery();

            int i = 0;

            res.last();
            x = res.getRow();

            s = new String[x][campos.length];
            // System.out.println("rows :" + x);
            res.beforeFirst();
            while (res.next()) {
                //   System.out.println("registro:"+i+"<-");
                for (int columna = 0; columna < campos.length; columna++) {

                    // System.out.println(columna + " " + campos[columna] + "\n");
                    s[i][columna] = res.getString(campos[columna]);

                }
                i++;
            }



        } catch (SQLException e) {
            System.out.println(e);
        }

        return s;
    }


    public boolean insertRegistro(String tabla, String campos,String valores){
        try {            
            PreparedStatement pstm = conn.getConnection().prepareStatement
                    ("insert into " + tabla+
                    "("+strcampos+") " +
                    " values(?,?,?,?)");    
            /*
            pstm.setString(1, name);
            pstm.setString(2, ap);
            pstm.setString(3, am);                        
            pstm.setString(4, mail);   
            */                     
            pstm.execute();
            pstm.close();            
         }catch(SQLException e){
         System.out.println(e);
      }

        
        return false;
               
    }
    
    
     public boolean actualizaRegistro(String tabla, String campos,String condiciones){
        
        
        return false;
               
    }
    

}
